package com.gxa.logistics.controller;


import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.*;
import com.gxa.logistics.domain.vo.VehicleVO;
import com.gxa.logistics.service.VehicleService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "车辆管理—车辆列表")
@RestController
@RequestMapping("/vehicle")
@Slf4j
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    /**
     * 获取用户列表
     */
    @ApiOperation(value = "获取车辆列表-分页", notes = "获取车辆列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo",value = "当前页码数",defaultValue = "1",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10",paramType = "query",dataType = "String")
    })
    @GetMapping("/list")
    public RespResult<PageWrapperDTO<VehicleVO>> list(VehicleReqListDTO vehicleReqListDTO){
        return vehicleService.list(vehicleReqListDTO);
    }

    /**
     * 新增车辆
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data",value = "系统用户添加实体") @Validated VehicleSaveDTO vehicleSaveDTO) {
        // 保存
        vehicleService.insertVehicle(vehicleSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data",value = "车辆修改实体") VehicleUpdateDTO vehicleUpdateDTO) {
        vehicleService.updateVehicle(vehicleUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除用户
     */
    @ApiOperation(value = "删除车辆", notes = "删除称量")
    @ApiImplicitParam(name = "lpnum",value = "车牌号码",required = true,dataType = "String",paramType = "path")
    @PostMapping("/delete/{lpnum}")
    public RespResult delete(@PathVariable("lpnum") String lpnum){
        vehicleService.delVehicleBylpnum(lpnum);
        return RespResult.success();
    }




}

